package com.ruoyi.basedata.service.impl;

import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basedata.mapper.BillSettlementMapper;
import com.ruoyi.basedata.domain.BillSettlement;
import com.ruoyi.basedata.service.IBillSettlementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * 费用结算Service业务层处理
 * 
 * @author gdqt
 * @date 2025-04-23
 */
@Service
public class BillSettlementServiceImpl extends ServiceImpl<BillSettlementMapper, BillSettlement> implements IBillSettlementService
{
    @Autowired
    private BillSettlementMapper billSettlementMapper;

    /**
     * 查询费用结算
     * 
     * @param id 费用结算主键
     * @return 费用结算
     */
    @Override
    public BillSettlement selectBillSettlementById(Long id)
    {

        return billSettlementMapper.selectById(id);
    }

    /**
     * 查询费用结算列表
     * 
     * @param billSettlement 费用结算
     * @return 费用结算
     */
    @Override
    public List<BillSettlement> selectBillSettlementList(BillSettlement billSettlement)
    {
        LambdaQueryWrapper<BillSettlement> queryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(billSettlement.getEnergyUseClassification())){
            queryWrapper.eq(BillSettlement::getEnergyUseClassification,billSettlement.getEnergyUseClassification());
        }
        if(!StringUtils.isEmpty(billSettlement.getUserId())){
            queryWrapper.eq(BillSettlement::getUserId,billSettlement.getUserId());
        }
        if(!StringUtils.isEmpty(billSettlement.getTerminalId())){
            queryWrapper.eq(BillSettlement::getTerminalId,billSettlement.getTerminalId());
        }
        if(billSettlement.getStartReading() != null){
            queryWrapper.eq(BillSettlement::getStartReading,billSettlement.getStartReading());
        }
        if(billSettlement.getEndReading() != null){
            queryWrapper.eq(BillSettlement::getEndReading,billSettlement.getEndReading());
        }
        if(billSettlement.getTotalVal() != null){
            queryWrapper.eq(BillSettlement::getTotalVal,billSettlement.getTotalVal());
        }
        if(billSettlement.getUnitPrice() != null){
            queryWrapper.eq(BillSettlement::getUnitPrice,billSettlement.getUnitPrice());
        }
        if(billSettlement.getLateFee() != null){
            queryWrapper.eq(BillSettlement::getLateFee,billSettlement.getLateFee());
        }
        if(billSettlement.getReadDate() != null){
            queryWrapper.eq(BillSettlement::getReadDate,billSettlement.getReadDate());
        }
        if(billSettlement.getStatus() != null){
            queryWrapper.eq(BillSettlement::getStatus,billSettlement.getStatus());
        }
        return billSettlementMapper.selectList(queryWrapper);
    }

    /**
     * 新增费用结算
     * 
     * @param billSettlement 费用结算
     * @return 结果
     */
    @Override
    public int insertBillSettlement(BillSettlement billSettlement)
    {
        return billSettlementMapper.insert(billSettlement);
    }

    /**
     * 修改费用结算
     * 
     * @param billSettlement 费用结算
     * @return 结果
     */
    @Override
    public int updateBillSettlement(BillSettlement billSettlement)
    {
        billSettlement.setUpdateTime(DateUtils.getNowDate());
        return billSettlementMapper.updateById(billSettlement);
    }

    /**
     * 批量删除费用结算
     * 
     * @param ids 需要删除的费用结算主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBillSettlementByIds(Long[] ids)
    {
        return billSettlementMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除费用结算信息
     * 
     * @param id 费用结算主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteBillSettlementById(Long id)
    {
        return billSettlementMapper.deleteById(id);
    }
}
